home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / usenet / sources / volume90 / devices / msh_1_5 / part01 / src / support.c < prev   
C/C++ Source or Header  |  1990-02-21  |  4KB  |  200 lines

  1. /*-
  2.  * $Id: support.c,v 1.2 90/02/03 17:01:19 Rhialto Exp $
  3.  * $Log:    support.c,v $
  4.  * Revision 1.2  90/02/03  17:01:19  Rhialto
  5.  * Add error checking in dosalloc()
  6.  * 
  7.  * Revision 1.1  89/12/17  19:57:50  Rhialto
  8.  * Initial revision
  9.  *
  10. -*/
  11.  
  12. #include "dos.h"
  13.  
  14. extern PORT    *DosPort;    /* Our DOS port... */
  15.  
  16. typedef unsigned long        ulong;
  17. typedef unsigned char        ubyte;
  18.  
  19. /*
  20.  * PACKET ROUTINES.    Dos Packets are in a rather strange format as you
  21.  * can see by this and how the PACKET structure is extracted in the
  22.  * GetMsg() of the main routine.
  23.  */
  24.  
  25. void
  26. returnpacket(packet)
  27. register struct DosPacket *packet;
  28. {
  29.     register struct Message *mess;
  30.     register struct MsgPort *replyport;
  31.  
  32.     replyport = packet->dp_Port;
  33.     mess = packet->dp_Link;
  34.     packet->dp_Port = DosPort;
  35.     mess->mn_Node.ln_Name = (char *) packet;
  36.     mess->mn_Node.ln_Succ = NULL;
  37.     mess->mn_Node.ln_Pred = NULL;
  38.     PutMsg(replyport, mess);
  39. }
  40.  
  41. /*
  42.  * Are there any packets queued to our device?
  43.  */
  44.  
  45. int
  46. packetsqueued()
  47. {
  48.     return ((void *) DosPort->mp_MsgList.lh_Head !=
  49.         (void *) &DosPort->mp_MsgList.lh_Tail);     /* & inserted by OIS */
  50. }
  51.  
  52. /*
  53.  * DOS MEMORY ROUTINES
  54.  */
  55.  
  56. void           *
  57. dosalloc(bytes)
  58. register ulong    bytes;
  59. {
  60.     register ulong *ptr;
  61.  
  62.     bytes += sizeof (*ptr);
  63.     if (ptr = AllocMem(bytes, MEMF_PUBLIC | MEMF_CLEAR)) {
  64.     *ptr = bytes;
  65.     return (ptr + 1);
  66.     }
  67.  
  68.     return NULL;
  69. }
  70.  
  71. dosfree(ptr)
  72. register ulong *ptr;
  73. {
  74.     --ptr;
  75.     FreeMem(ptr, *ptr);
  76. }
  77.  
  78. /*
  79.  * Convert a BSTR into a normal string.. copying the string into buf. I
  80.  * use normal strings for internal storage, and convert back and forth
  81.  * when required.
  82.  */
  83.  
  84. void
  85. btos(bstr, buf)
  86. ubyte           *bstr;
  87. ubyte           *buf;
  88. {
  89.     bstr = BTOC(bstr);
  90.     bmov(bstr + 1, buf, *bstr);
  91.     buf[*bstr] = 0;
  92. }
  93.  
  94. /*
  95.  * Some EXEC list handling routines not found in the EXEC library.
  96.  */
  97.  
  98. #ifdef notdef
  99.  
  100. void           *
  101. NextNode(node)
  102. register NODE        *node;
  103. {
  104.     node = node->mln_Succ;
  105.     if (node->mln_Succ == NULL)
  106.     return (NULL);
  107.     return (node);
  108. }
  109.  
  110. #endif
  111.  
  112. void           *
  113. GetHead(list)
  114. register LIST        *list;
  115. {
  116.     if ((void *) list->mlh_Head != (void *) &list->mlh_Tail)
  117.     return (list->mlh_Head);
  118.     return (NULL);
  119. }
  120.  
  121. void           *
  122. GetTail(list)
  123. register LIST        *list;
  124. {
  125.     if ((void *) list->mlh_Head != (void *) &list->mlh_Tail)
  126.     return (list->mlh_TailPred);
  127.     return (NULL);
  128. }
  129.  
  130. #ifdef DEBUG
  131. char           *
  132. typetostr(ty)
  133. long ty;
  134. {
  135.     switch (ty) {
  136.     case ACTION_DIE:
  137.     return ("DIE");
  138.     case ACTION_CURRENT_VOLUME:
  139.     return ("CURRENT VOLUME");
  140.     case ACTION_OPENRW:
  141.     return ("OPEN-RW");
  142.     case ACTION_OPENOLD:
  143.     return ("OPEN-OLD");
  144.     case ACTION_OPENNEW:
  145.     return ("OPEN-NEW");
  146.     case ACTION_READ:
  147.     return ("READ");
  148.     case ACTION_WRITE:
  149.     return ("WRITE");
  150.     case ACTION_CLOSE:
  151.     return ("CLOSE");
  152.     case ACTION_SEEK:
  153.     return ("SEEK");
  154.     case ACTION_EXAMINE_NEXT:
  155.     return ("EXAMINE NEXT");
  156.     case ACTION_EXAMINE_OBJECT:
  157.     return ("EXAMINE OBJ");
  158.     case ACTION_INFO:
  159.     return ("INFO");
  160.     case ACTION_DISK_INFO:
  161.     return ("DISK INFO");
  162.     case ACTION_PARENT:
  163.     return ("PARENTDIR");
  164.     case ACTION_DELETE_OBJECT:
  165.     return ("DELETE");
  166.     case ACTION_CREATE_DIR:
  167.     return ("CREATEDIR");
  168.     case ACTION_LOCATE_OBJECT:
  169.     return ("LOCK");
  170.     case ACTION_COPY_DIR:
  171.     return ("DUPLOCK");
  172.     case ACTION_FREE_LOCK:
  173.     return ("FREELOCK");
  174.     case ACTION_SET_PROTECT:
  175.     return ("SETPROTECT");
  176.     case ACTION_SET_COMMENT:
  177.     return ("SETCOMMENT");
  178.     case ACTION_RENAME_OBJECT:
  179.     return ("RENAME");
  180.     case ACTION_INHIBIT:
  181.     return ("INHIBIT");
  182.     case ACTION_RENAME_DISK:
  183.     return ("RENAME DISK");
  184.     case ACTION_MORECACHE:
  185.     return ("MORE CACHE");
  186.     case ACTION_WAIT_CHAR:
  187.     return ("WAIT FOR CHAR");
  188.     case ACTION_FLUSH:
  189.     return ("FLUSH");
  190.     case ACTION_RAWMODE:
  191.     return ("RAWMODE");
  192.     case ACTION_SET_DATE:
  193.     return ("SET_DATE");
  194.     default:
  195.     return ("---------UNKNOWN-------");
  196.     }
  197. }
  198.  
  199. #endif                /* DEBUG */
  200.